/**
 *  @file BaseExceptions.h
 */
#ifndef _BASEEXCEPTION_H_
#define _BASEEXCEPTION_H_

#include "../common/BaseObject.h"

namespace cppflib
{

class CFString;

namespace exceptions
{

class _DLLAPI BaseException : public BaseObject
{
private:
    CFString * message;
    int errCode;

protected:
    void SetMsg(pcwstr_t message);
    void SetErrCode(int errCode);

public:
    BaseException(void);
    explicit BaseException(pcwstr_t message);
    BaseException(pcwstr_t message, int errCode);
    BaseException(const BaseException &exp);
    virtual ~BaseException(void);

    pcwstr_t GetMsg();
    int GetErrCode();

    void *operator new(sz_t size);
    void operator delete(void *p);
    void *operator new[](sz_t size);
    void operator delete[](void *p);
};


/**
 *  Declare exception in header
 */
#define DECLARE_EXCEPTION_H(expName) \
   class _DLLAPI expName : public exceptions::BaseException\
   {\
   private:\
       expName(void);\
   public:\
       explicit expName(pcwstr_t message);\
       expName(pcwstr_t message, int errCode);\
       virtual ~expName(void);\
   };

/**
 *  Implement exception in cpp file
 */
#define IMPLEMENT_EXCEPTION_CPP(expName) \
   expName::expName(void) { } \
   expName::expName(pcwstr_t message) : BaseException(message, -1) { } \
   expName::expName(pcwstr_t message, int errCode) : BaseException(message, errCode) { } \
   expName::~expName(void) { }



}  // end of namespace exceptions

}  // end of namespace cppflib

#endif
